﻿// ----------------------- visitors factory class -------------------------------------------
MapControl2.AAAVisitorFactory = function()
{
    this._visitors = new Array();
};

MapControl2.AAAVisitorFactory.prototype = {

    /* 
        creates a visitor of type <visitor_type> with the given parameters. The possible 
        visitor types are defined at the end of this file. <visitor_params> is an array
        of parameters that must be passed to visitor constructor.
    */
    createVisitor: function(visitor_type, visitor_params)
    {
        var visitor = this._visitors[visitor_type];
        if(visitor)
        {
            return visitor;
        }else{
        
            // builds the constructor command and evaluates it
            var toEval = 'visitor = new ' + visitor_type;
            var params = ' ';
            if (visitor_params)
            {
                params = visitor_params.join(', ');
            }
            toEval += '(' + params + ')';
            eval(toEval);
           
            this._visitors[visitor_type] = visitor;
            return visitor;
        }
    }
};

// possible visitor types
MapControl2.AAAVisitorFactory.JSON_SERIALIZER_VISITOR = "MapControl2.AAAJsonSerializerVisitor";
MapControl2.AAAVisitorFactory.MARKERS_FORMATTER_VISITOR = "MapControl2.AAAMarkersFormatterVisitor";

MapControl2.AAAVisitorFactory.registerClass('MapControl2.AAAVisitorFactory');
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();